#include <iostream>
using namespace std;

int main() {
    const int MAX = 30000;
    int t;
    bool p[MAX];
    for (int i = 0; i < MAX; i++)
        p[i] = !(i == 0 || i == 1);
    for (int i = 2; i < MAX; i++) {
        if (p[i])
            for (int j = 2; i * j < MAX; j++)
                p[i * j] = false;
    }

    cin >> t;
    while (t-- > 0) {
        int d, a, b;
        cin >> d;
        a = 1 + d;
        while (!p[a])
            a++;
        b = a + d;
        while (!p[b])
            b++;

        cout << a * b << endl;
    }
    return 0;
}